from django.db import models

# Create your models here.


class Admin(models.Model):
    """
    管理员表
    """
    username = models.CharField(verbose_name="用户名",max_length=32)
    password = models.CharField(verbose_name="密码",max_length=64)

    def __str__(self):
        return self.username


class Department(models.Model):
    """
    部门表
    """
    titile = models.CharField(verbose_name="标题",max_length=32)

    def __str__(self):
        """
        __str__方法用于返回对象的描述信息
        """
        return self.titile


class UserInfo(models.Model):
    """
    员工表
    """
    name = models.CharField(verbose_name="姓名",max_length=32)
    password = models.CharField(verbose_name="密码",max_length=64)
    age = models.IntegerField(verbose_name="年龄")

    # 在django中做约束 性别只能二选一
    gender_tup = (
        (1,"男"),
        (2,"女"),
    )
    gender = models.SmallIntegerField(verbose_name="性别",choices=gender_tup)

    salary = models.DecimalField(verbose_name="工资",max_digits=10,decimal_places=2,default=0)
    create_time = models.DateTimeField(verbose_name="入职时间")

    # 无约束
    # deparment_id = models.BigIntegerField(verbose_name="部门id")
    # 1.有约束
    # -to, 与那张表有关联
    # -to_field,表中的那一列关联e
    # 2、django自动
    # - 写的depart
    # - 生成数据列 depart_id
    # 3、部门表被删除
    #### 3.1 级联删除(与这个表相关联的数据都删除) models.CASCADE()
    depart = models.ForeignKey(to="Department",to_field="id",on_delete=models.CASCADE,verbose_name="部门")
    #### 3.2 置空(让关联的数据为空，首先你得允许这一列为空) models.SET_NULL
    # depart = models.ForeignKey(to="Department",to_field="id",null=True,blank=True,on_delete=models.SET_NULL)



class PrettyNum(models.Model):
    """
    靓号管理
    """
    mobile = models.CharField(verbose_name="手机号",max_length=11)
    price = models.DecimalField(verbose_name="价格",max_digits=10,decimal_places=2,default=0)

    level_choices = (
        (1,"一级"),
        (2,"二级"),
        (3,"三级"),
        (4,"四级"),
    )
    level = models.SmallIntegerField(verbose_name="级别",choices=level_choices,default=1)

    status_choices = (
        (1,"已占用"),
        (2,"未使用")
    )
    status = models.SmallIntegerField(verbose_name="状态",choices=status_choices,default=2)


class Task(models.Model):
    """
    任务管理表
    """
    title = models.CharField(verbose_name="任务标题",max_length=64)
    detail = models.TextField(verbose_name="任务详细信息")
    level_choice = (
        (1,"紧急"),
        (2,"重要"),
        (2,"临时"),
    )
    level = models.SmallIntegerField(verbose_name="任务级别",choices=level_choice,default=1)
    # 关联Admin表
    user = models.ForeignKey(verbose_name="负责人",to="Admin",on_delete=models.CASCADE,to_field="id")



class Order(models.Model):
    """
    订单表
    """
    oid = models.CharField(verbose_name="订单号",max_length=64)
    title = models.CharField(verbose_name="商品名称",max_length=32)
    price = models.IntegerField(verbose_name="价格")
    status_choice = (
        (1,"待支付"),
        (2,"已支付"),
    )
    status = models.SmallIntegerField(verbose_name="状态",choices=status_choice,default=1)
    # 关联Admin表
    admin = models.ForeignKey(verbose_name="管理员",to="Admin",to_field="id",on_delete=models.CASCADE)


class Boss(models.Model):
    """
    文件上传Form对应的表
    """
    name = models.CharField(verbose_name="姓名",max_length=32)
    age = models.IntegerField(verbose_name="年龄")
    img = models.CharField(verbose_name="头像",max_length=120)


class City(models.Model):
    """
    文件上传ModelForm对应的表
    """
    name = models.CharField(verbose_name="名称",max_length=64)
    count = models.IntegerField(verbose_name="人口")
    gdp = models.IntegerField(verbose_name="GDP")

    # FileField本质上数据也是CharField，自动保存数据(FileField类型的话就不用在views.py文件进行保存的操作)
    # upload_to会将数据保存在media下面的目录中
    img = models.FileField(verbose_name="LOGO",max_length=128,upload_to="city/")

















